import 'package:flutter/material.dart';

class InfiniteTest extends StatefulWidget {
  @override
  _InfiniteTestState createState() => _InfiniteTestState();
}

class _InfiniteTestState extends State<InfiniteTest>
    with TickerProviderStateMixin {
  late AnimationController _controller;
  late Animation<double> _animation;

  final Duration _duration = Duration(milliseconds: 1000);

  final Curve _curve = Curves.linear;

  @override
  void initState() {
    super.initState();

    _controller = AnimationController(
      vsync: this,
      duration: _duration,
    );

    _animation = Tween<double>(
      begin: 0,
      end: 1,
    ).animate(CurvedAnimation(
      curve: _curve,
      parent: _controller,
    ));
  }

  @override
  void dispose() {
    _controller.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 8),
      height: 300,
      child: Column(
        children: [
          Expanded(
            child: Container(
              alignment: Alignment.center,
              child: RotationTransition(
                turns: _animation,
                child: Container(
                  width: 50,
                  height: 50,
                  color: Colors.blueGrey,
                ),
              ),
            ),
          ),
          TextButton(
            onPressed: () {
              if (_controller.isAnimating) {
                _controller.stop();
              } else {
                _controller.repeat();
              }
            },
            child: Text('点击'),
          ),
        ],
      ),
    );
  }
}
